package com.ihealthway.all.groupbuy.services;

import com.ihealthway.all.groupbuy.vo.ShopAd;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import java.util.Date;
import java.util.List;

/**
 * Shop ad service
 *
 * @author 凡梦星尘(elkan1788@gmail.com)
 */
@IocBean(fields = {"dao"})
public class ShopAdService extends BaseService<ShopAd> {

    private static final Log logger = Logs.get();

    public boolean updateAdImg(ShopAd shopAd) {

        boolean update = false;

        shopAd.setUpdateTime(new Date());
        try {
            int effectRows = _updateIgnoreNull(shopAd);
            update = (effectRows > 0);
        } catch (Exception e) {
            logger.error(shopAd);
            logger.error("Update shop ad image failed.", e);
        }

        return update;
    }

    public boolean update(List<ShopAd> shopAds) {

        boolean update = false;

        for (ShopAd ad : shopAds) {
            ad.setUpdateTime(new Date());
        }

        try {
            int effectRows = dao().updateIgnoreNull(shopAds);
            update = (effectRows > 0);
        } catch (Exception e) {
            logger.error(shopAds);
            logger.error("Update shop ad info failed.", e);
        }

        return update;
    }
}
